/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package conexaobancodedados;

/**
 *
 * @author fosa
 */
//import com.mysql.jdbc.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class Conect1 {

    private String Gluser;
    private String Glpassword;
    private String Gllocal;
    private String Glbanco;
    private Statement Glconexão;

    public int connect() {
        int ret = 1;
        try {
            Class.forName("org.postgresql.Driver").newInstance();
            Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://" + getGllocal() + ":3306/" + getGlbanco(), getGluser(), getGlpassword());
//            Connection con = (Connection) DriverManager.getConnection("jdbc:postgresql://" + getGllocal() + ":5432/" + getGlbanco(), getGluser(), getGlpassword());
            setGlconexão((Statement) con.createStatement());
//            (com.mysql.jdbc.Statement)
        } catch (InstantiationException ex) {
            System.out.println("Houve erro no iniciando a conexão");
            ret = -1;
        } catch (IllegalAccessException ex) {
            System.out.println("Houve erro no acessando a conexão");
            ret = -1;
        } catch (ClassNotFoundException ex) {
            System.out.println("Houve erro no nao encontrou a conexão");
            ret = -1;
        } catch (SQLException e) {
            System.out.println("Houve erro SQLException sem conexao ao banco de dados");
            e.printStackTrace();
            ret = -1;
        }
        return ret;
    }

    /**
     * @return the Gluser
     */
    public String getGluser() {
        return Gluser;
    }

    /**
     * @param Gluser the Gluser to set
     */
    public void setGluser(String Gluser) {
        this.Gluser = Gluser;
    }

    /**
     * @return the Glpassword
     */
    public String getGlpassword() {
        return Glpassword;
    }

    /**
     * @param Glpassword the Glpassword to set
     */
    public void setGlpassword(String Glpassword) {
        this.Glpassword = Glpassword;
    }

    /**
     * @return the Gllocal
     */
    public String getGllocal() {
        return Gllocal;
    }

    /**
     * @param Gllocal the Gllocal to set
     */
    public void setGllocal(String Gllocal) {
        this.Gllocal = Gllocal;
    }

    /**
     * @return the Glconexão
     */
    public Statement getGlconexão() {
        return Glconexão;
    }

    /**
     * @param Glconexão the Glconexão to set
     */
    public void setGlconexão(Statement Glconexão) {
        this.Glconexão = Glconexão;
    }

    /**
     * @return the Glbanco
     */
    public String getGlbanco() {
        return Glbanco;
    }

    /**
     * @param Glbanco the Glbanco to set
     */
    public void setGlbanco(String Glbanco) {
        this.Glbanco = Glbanco;
    }
}
